// app.ts
App<IAppOption>({
  globalData: {
      title:'张三'
  },
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        console.log(res.code)
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      },
    })
  },
  // 全局方法：处理点击事件
  handleTapEvent(event: WechatMiniprogram.TouchEvent, callback: (dataset: Record<string, any>) => void) {
    const { target } = event;
    const dataset = target?.dataset || {};
    const currentTarget = event.currentTarget || {};
    const currentTargetDataset = currentTarget?.dataset || {};

    // 合并 target 和 currentTarget 的 dataset
    const mergedDataset = { ...dataset, ...currentTargetDataset };

    // 调用回调函数并传递合并后的 dataset
    if (typeof callback === 'function') {
      callback(mergedDataset);
    }
  }
  
})

/*
onTap(event: WechatMiniprogram.TouchEvent) {
      const app = getApp(); // 获取 app.ts 的实例
      app.handleTapEvent(event, (dataset) => {
        // 在这里处理 dataset
        console.log('Dataset:', dataset);
      });
    },
*/